﻿using System;
using System.Collections.Generic;
using Bankeren.Engine.Cards;
using Bankeren.Service;

namespace Bankeren.Engine
{
    public abstract class Player : IBankerenCallback
    {
        #region Fields

        protected Game game;
        protected PlayerInfo info;
        protected Hand hand;
        protected int mySeat;

        #endregion

        #region Properties

        public PlayerInfo Info
        {
            get
            {
                return this.info;
            }
            set
            {
                this.info = value;
            }
        }

        public Hand Hand
        {
            get
            {
                return this.hand;
            }
        }

        public int Seat
        {
            get
            {
                return this.mySeat;
            }
        }

        #endregion

        #region Ctor

        public Player(Game game, PlayerInfo info, int seat)
        {
            this.game = game;
            this.info = info;
            this.hand = new Hand();
            this.mySeat = seat;
        }

        #endregion

        #region Methods

        #region Callback Methods

        public abstract void Welcome(int seat, Dictionary<int, PlayerInfo> players);
        public abstract void PlayerJoined(int seat, PlayerInfo info);
        public abstract void PlayerInfoChanged(int seat, PlayerInfo info);
        public abstract void PlayerLeft(int seat);
        public abstract void GameStarted();
        public abstract void RoundStarted(int roundNumber, int numCards, int dealerSeat, Card trump);
        public abstract void Bids(Dictionary<int, int> bids);
        public abstract void TrickStarted(int trickNumber);
        public abstract void Turn(int seat, Suit followSuit);
        public abstract void CardPlayed(int seat, Card card);
        public abstract void TrickEnded(int winner);
        public abstract void RoundEnded(Dictionary<int, int> points);
        public abstract void GameEnded(int winner);
        public abstract void Chat(int seat, string message);
        public abstract void ServerStopped(string message);

        public virtual void DealCards(List<Card> cards)
        {
            hand.AddRange(cards);
        }

        #endregion

        public override string ToString()
        {
            return this.info.Name;
        }

        #endregion
    }
}
